<!DOCTYPE html>
<html>
<head>
<title>角色添加修改</title>
<meta name="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" charset="UTF-8" src="../../../easyui/jquery.min.js"></script>
<link rel="stylesheet" id="easyuiTheme" href="../../../easyui/themes/default/easyui.css" type="text/css"></link>
<link rel="stylesheet" id="easyuiTheme" href="../../../easyui/themes/icon.css" type="text/css"></link>
<script type="text/javascript" src="../../../easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../../easyui/locale/easyui-lang-zh_CN.js"></script>

<link rel="stylesheet" href="../../../style/syExtIcon.css" type="text/css"></link>
<link rel="stylesheet" href="../../../style/syExtCss.css" type="text/css"></link>
<script type="text/javascript" src="../../../js/ExtEasyui.js"></script>
<script type="text/javascript" src="../../../js/Extjs.js"></script>
<script type="text/javascript">
var resourceTree;
$(function(){
	resourceTree = $('#resourceTree').tree({
		method: 'get',
		url : '/menu/allTree',
		parentField : 'pid',
		checkbox : true,
		onCheck : function(node, checked) {
			var nodes = resourceTree.tree('getChecked');
            var s1 = '';
            for(var i=0; i<nodes.length; i++){
                if (s1 != '') s1 += ',';
                s1 += nodes[i].id;
            }
            $("#menuIds").val(s1);
		},
		onLoadSuccess : function(node, data) {
			var menuIds = $("#menuIds").val();
			var ids = $.stringToList(menuIds);
			if (ids.length > 0) {
				for ( var i = 0; i < ids.length; i++) {
					if (resourceTree.tree('find', ids[i])) {
						resourceTree.tree('check', resourceTree.tree('find', ids[i]).target);
					}
				}
			}
		},
		cascadeCheck : true
	});
});
var roleAdd_submitForm = function(dialog, role_treeGrid, p) {
	if ($('role_addForm').form('validate')) {
		$.post('/role/add', $("#role_addForm").serialize(), function(j) {
			if (j.success) {
				role_treeGrid.datagrid('reload');
				dialog.dialog('destroy');
			}
			p.messager.show({
				title : '提示',
				msg : j.msg,
				timeout : 5000,
				showType : 'slide'
			});
		}, 'json');
	}
};

function AllChecked(a){
	$("#ch"+a).children().each(function(){
		if(this.checked==true){
			this.checked=false;
		}else{
			this.checked=true;
		}
	});
}
</script>
</head>

<body>
	<form id="role_addForm" method="post">
	<input type="hidden" id="roleId" name="id" value="{role.id ?: ''}"/>
		<table style="width: 100%;">
			<tr>
				<th>角色名称</th>
				<td><input id="roleName" name="name" value="{role.name ?: ''}" class="easyui-validatebox"
					data-options="required:true,missingMessage:'角色名称必填'" /></td>
			</tr>
			<tr>
				<th>备注</th>
				<td><input name="remark" value="{role.remark ?: ''}"/></td>
			</tr>
		</table>
	
	<fieldset><legend>权限选择</legend>
	    <ul id="resourceTree"></ul>
	</fieldset>
	<input type="hidden" name="menuIds" id="menuIds" value="{role.menuIds ?: ''}"/>
	</form>
</body>
</html>